package LinkedList;


import java.util.LinkedList;

/**
 * 使用JDK中的LinkedList
 */
public class LinkedListTest {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();

        //添加元素
        linkedList.add("str元素1");
        linkedList.add("str元素2");
        linkedList.add("str元素3");
        linkedList.add("str元素4");

        //for遍历
        System.out.println("for遍历");
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }

        //foreach遍历
        System.out.println("foreach遍历");
        for (Object o : linkedList)
            System.out.println(o);

        //也可用pollFirst()和removeFirst()遍历，此处省略

        //获取元素
        linkedList.get(1);

        System.out.println("使用pollFirst()");
        linkedList.pollFirst();
        linkedList.removeFirst();


    }
}
